{% load static %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>{% block title %}登录 - METTLER TOLEDO Service{% endblock %}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">

{% block extra_css %}
<style>
/* 登录页面专用样式 */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    padding: 2rem 0;
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="50" cy="50" r="0.5" fill="%23ffffff" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>') repeat;
    animation: float 20s ease-in-out infinite;
    z-index: 1;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(2%, -2%) rotate(1deg); }
    66% { transform: translate(-2%, 2%) rotate(-1deg); }
}

.login-container {
    position: relative;
    z-index: 2;
    max-width: 450px;
    margin: 0 auto;
}

.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s ease;
}

.login-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.15);
}

.login-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    position: relative;
}

.login-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="%23ffffff" opacity="0.1"/><circle cx="80" cy="80" r="1.5" fill="%23ffffff" opacity="0.1"/><circle cx="60" cy="30" r="1" fill="%23ffffff" opacity="0.1"/></svg>') repeat;
}

.login-logo {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 2rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.brand-text {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1;
}

.brand-subtitle {
    margin: 0.5rem 0 0;
    font-size: 0.9rem;
    opacity: 0.9;
    font-weight: 300;
    position: relative;
    z-index: 1;
}

.login-body {
    padding: 2.5rem;
}

.welcome-text {
    text-align: center;
    margin-bottom: 2rem;
    color: #6c757d;
    font-size: 1rem;
}

.form-floating {
    margin-bottom: 1.5rem;
}

.form-floating > .form-control {
    height: 58px;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-floating > .form-control:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.15);
    transform: translateY(-1px);
}

.form-floating > label {
    color: #6c757d;
    font-weight: 500;
}

.input-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #adb5bd;
    z-index: 4;
    transition: color 0.3s ease;
}

.form-floating > .form-control:focus ~ .input-icon {
    color: #667eea;
}

.login-btn {
    width: 100%;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.login-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.login-btn:hover::before {
    left: 100%;
}

.login-btn:active {
    transform: translateY(0);
}

.divider {
    text-align: center;
    margin: 2rem 0;
    position: relative;
    color: #adb5bd;
    font-size: 0.9rem;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e9ecef;
    z-index: 1;
}

.divider span {
    background: white;
    padding: 0 1rem;
    position: relative;
    z-index: 2;
}

.register-link {
    text-align: center;
    margin-top: 1.5rem;
}

.register-link a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.register-link a:hover {
    color: #764ba2;
    text-decoration: underline;
}

.footer-text {
    text-align: center;
    margin-top: 2rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.footer-text i {
    margin-right: 0.5rem;
    color: rgba(255, 255, 255, 0.6);
}

/* 响应式设计 */
@media (max-width: 576px) {
    .login-container {
        padding: 0 1rem;
    }
    
    .login-header {
        padding: 1.5rem;
    }
    
    .login-body {
        padding: 2rem 1.5rem;
    }
    
    .brand-text {
        font-size: 1.3rem;
    }
    
    .login-logo {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
}

/* 加载动画 */
.login-loading {
    opacity: 0.7;
    pointer-events: none;
}

.login-loading .login-btn {
    background: #6c757d;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
</style>
{% endblock %}

<body>
    <!-- 登录页面内容 -->
    {% block login_content %}
    <div class="login-page">
        <div class="login-container">
            <!-- 主登录卡片 -->
            <div class="login-card">
                <!-- 卡片头部 -->
                <div class="login-header">
                    <div class="login-logo">
                        <i class="fas fa-shield-alt"></i>
                    </div>
                    <h1 class="brand-text">
                        <span style="color: #ffffff;">METTLER TOLEDO</span>
                        <span style="color: #66CC99; margin-left: 0.25rem;">Service</span>
                    </h1>
                    
                </div>
                
                <!-- 卡片主体 -->
                <div class="login-body">
                    <div class="welcome-text">
                        <h5 class="mb-2 text-dark">欢迎回来！</h5>
                        <p class="mb-0">请登录您的账户以继续</p>
                    </div>
                    
                    <!-- 登录表单 -->
                    <form method="POST" id="loginForm">
                        {% csrf_token %}
                        
                        <!-- 邮箱输入 -->
                        <div class="form-floating">
                            <input type="email" class="form-control" id="email" name="email" 
                                   placeholder="请输入邮箱地址" required>
                            <label for="email">邮箱地址</label>
                            <i class="fas fa-envelope input-icon"></i>
                        </div>
                        
                        <!-- 密码输入 -->
                        <div class="form-floating">
                            <input type="password" class="form-control" id="password" name="password" 
                                   placeholder="请输入密码" required>
                            <label for="password">密码</label>
                            <i class="fas fa-lock input-icon"></i>
                        </div>
                        
                        <!-- 记住我 和 忘记密码 -->
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="rememberMe">
                                <label class="form-check-label text-muted" for="rememberMe">
                                    记住我
                                </label>
                            </div>
                            <a href="#" class="text-muted text-decoration-none small" onclick="showForgotPassword()">
                                忘记密码？
                            </a>
                        </div>
                        
                        <!-- 登录按钮 -->
                        <button type="submit" class="login-btn" id="loginButton">
                            <i class="fas fa-sign-in-alt me-2"></i>登录系统
                        </button>
                    </form>
                    
                    <!-- 分隔线 -->
                    <div class="divider">
                        <span>或</span>
                    </div>
                    
                    <!-- 注册链接 -->
                    <div class="register-link">
                        <p class="mb-0 text-muted">
                            还没有账户？ 
                            <a href="{{ register_url }}">立即注册</a>
                        </p>
                    </div>
                </div>
            </div>
            
            <!-- 底部信息 -->
            <div class="footer-text">
                <i class="fas fa-shield-alt"></i>
                由 METTLER TOLEDO Service 提供技术支持
            </div>
        </div>
    </div>
    {% endblock %}

    {% block extra_js %}
    <script>
    // 登录页面交互功能
    document.addEventListener('DOMContentLoaded', function() {
        const loginForm = document.getElementById('loginForm');
        const loginButton = document.getElementById('loginButton');
        const emailInput = document.getElementById('email');
        const passwordInput = document.getElementById('password');
        
        // 表单提交处理
        loginForm.addEventListener('submit', function(e) {
            if (!validateForm()) {
                e.preventDefault();
                return false;
            }
            
            // 显示加载状态
            showLoading();
        });
        
        // 表单验证
        function validateForm() {
            let isValid = true;
            
            // 验证邮箱
            const email = emailInput.value.trim();
            if (!email) {
                showFieldError(emailInput, '请输入邮箱地址');
                isValid = false;
            } else if (!isValidEmail(email)) {
                showFieldError(emailInput, '请输入有效的邮箱地址');
                isValid = false;
            } else {
                clearFieldError(emailInput);
            }
            
            // 验证密码
            const password = passwordInput.value.trim();
            if (!password) {
                showFieldError(passwordInput, '请输入密码');
                isValid = false;
            } else if (password.length < 6) {
                showFieldError(passwordInput, '密码至少需要 6 个字符');
                isValid = false;
            } else {
                clearFieldError(passwordInput);
            }
            
            return isValid;
        }
        
        // 邮箱格式验证
        function isValidEmail(email) {
            const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            return emailRegex.test(email);
        }
        
        // 显示字段错误
        function showFieldError(field, message) {
            clearFieldError(field);
            field.classList.add('is-invalid');
            
            const errorDiv = document.createElement('div');
            errorDiv.className = 'invalid-feedback';
            errorDiv.textContent = message;
            field.parentNode.appendChild(errorDiv);
        }
        
        // 清除字段错误
        function clearFieldError(field) {
            field.classList.remove('is-invalid');
            const errorDiv = field.parentNode.querySelector('.invalid-feedback');
            if (errorDiv) {
                errorDiv.remove();
            }
        }
        
        // 显示加载状态
        function showLoading() {
            document.querySelector('.login-page').classList.add('login-loading');
            loginButton.innerHTML = '<span class="spinner"></span>登录中...';
            loginButton.disabled = true;
        }
        
        // 隐藏加载状态
        function hideLoading() {
            document.querySelector('.login-page').classList.remove('login-loading');
            loginButton.innerHTML = '<i class="fas fa-sign-in-alt me-2"></i>登录系统';
            loginButton.disabled = false;
        }
        
        // 输入框实时验证
        emailInput.addEventListener('blur', function() {
            const email = this.value.trim();
            if (email && !isValidEmail(email)) {
                showFieldError(this, '请输入有效的邮箱地址');
            } else {
                clearFieldError(this);
            }
        });
        
        passwordInput.addEventListener('blur', function() {
            const password = this.value.trim();
            if (password && password.length < 6) {
                showFieldError(this, '密码至少需要 6 个字符');
            } else {
                clearFieldError(this);
            }
        });
        
        // 键盘快捷键
        document.addEventListener('keydown', function(e) {
            if (e.key === 'Enter' && (emailInput === document.activeElement || passwordInput === document.activeElement)) {
                e.preventDefault();
                loginForm.dispatchEvent(new Event('submit'));
            }
        });
        
        // 动画初始化
        setTimeout(() => {
            document.querySelector('.login-card').style.opacity = '1';
            document.querySelector('.login-card').style.transform = 'translateY(0)';
        }, 100);
        
        console.log('✨ 登录页面初始化完成');
    });

    // 忘记密码功能
    function showForgotPassword() {
        alert('🔒 忘记密码功能即将推出，请联系管理员重置密码。');
    }

    // 页面加载错误处理
    window.addEventListener('error', function(e) {
        console.error('页面加载错误:', e.error);
    });
    </script>
    {% endblock %}
</body>
</html>